﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Admin
{
    public partial class AdminForm : Form
    {
        ManagerService.ManagerService servicio = null;

        public AdminForm()
        {
            InitializeComponent();
            servicio = new ManagerService.ManagerService();
        }

        private void btnQuitar_Click(object sender, EventArgs e)
        {
            ManagerService.ServerNode servidor = new ManagerService.ServerNode();
            servidor.Nombre = txtNombreQuitar.Text;
            servidor.URL = txtURLQuitar.Text;

            lblResultado2.ForeColor = Color.Black;
            if (servicio.RemoveServer(servidor))
            {
                lblResultado2.ForeColor = Color.Black;
                lblResultado2.Text = "OK";
            }
            else
            {
                lblResultado2.ForeColor = Color.Red;
                lblResultado2.Text = "ERROR";
            }
        }

        private void btnAgregar_Click(object sender, EventArgs e)
        {
            ManagerService.ServerNode servidor = new ManagerService.ServerNode();
            
            servidor.Nombre = txtNombreAgregar.Text;
            servidor.URL = txtURLAgregar.Text;

            lblResultado2.ForeColor = Color.Black;
            if (servicio.AddServer(servidor))
            {
                lblResultado.ForeColor = Color.Black;
                lblResultado.Text = "OK";
            }
            else
            {
                lblResultado.ForeColor = Color.Red;
                lblResultado.Text = "ERROR";
            }
        }
        #region //Func auxiliares de GUI

        private void agregarServidorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            grpQuitar.Visible = false;
            grpAgregar.Visible = true;
            VaciarControles();
        }
        private void quitarServidorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Controls.Add(this.grpQuitar);
            grpAgregar.Visible = false;
            grpQuitar.Visible = true;
            VaciarControles();
        }
        private void VaciarControles()
        {
            txtNombreAgregar.Text = "";
            txtNombreQuitar.Text = "";
            txtURLAgregar.Text = "";
            txtURLQuitar.Text = "";
            lblResultado.Text = "";
            lblResultado2.Text = "";
        }


        private void salirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        
        #endregion

       

       

        

    }
}
